using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls.Maps.Platform;

namespace BingleMaps.Converters
{
	public class RouteLocationCollectionConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value is IEnumerable<Location>)
			{
				var collection = new LocationCollection();
				foreach (var geo in ((IEnumerable<Location>)value).Select(l => new GeoCoordinate(l.Latitude, l.Longitude)))
					collection.Add(geo);
				return collection;
			}
			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotSupportedException();
		}
	}
}